﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Management_ChargeNurse_WaitingList : System.Web.UI.Page
{

    static int currentPatient;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int ID = ((Authentication)Session[GlobalConstant.LOGIN_STATE]).userID; 
            int IDWard = Management_Danhsachnhanvien.getIDWardFromIDStaff(ID);
            benhnhanDS.SelectParameters["IDWard"].DefaultValue=IDWard.ToString();           
            GridView1.DataBind();

            //load room

            SqlConnection con = new SqlConnection(GlobalConstant.CONNECTION_STRING);
            con.Open();
            string sql = "SELECT [RoomName], [ID] FROM [tbRoom] WHERE IDWard=" + IDWard + " ORDER BY [RoomName]";
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader reader = cmd.ExecuteReader();
            liRoom.DataSource = reader;
            liRoom.DataTextField = "RoomName";
            liRoom.DataValueField = "ID";
            liRoom.DataBind();
            room_changed(null, null);
            con.Close();
        }
    }

    protected void benhnhan_click(object sender, EventArgs e)
    {
        currentPatient = Int32.Parse((sender as LinkButton).CommandArgument);
        pnRoom.Visible = true;
    }

    protected void room_changed(object sender, EventArgs e)
    {
        Bed1.loadFreeBedByRoomID(Int32.Parse(liRoom.SelectedValue));
    }
    protected void btSetBed_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(GlobalConstant.CONNECTION_STRING);
        con.Open();
        string sql = "UPDATE tbImpatient SET IDBed="+Bed1.SelectedValue+" WHERE IDPatient=" + currentPatient;
        SqlCommand cmd = new SqlCommand(sql, con);
        cmd.ExecuteNonQuery();
        con.Close();
        pnRoom.Visible = false;
        GridView1.DataBind();
    }
}